package cn.zcy.conno;


import com.mysql.jdbc.JDBC4Connection;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.Properties;

/**
 * 自定义连接对象
 * <p>
 * ，定义一个类，继承JDBC4Connection
 * 定义Connection连接对象和容器对象的成员
 * 通过有参方法给成员变量赋值
 * 重写close方法，完成归还连接
 */
public class MyConnection1 extends JDBC4Connection {
    private Connection connection;

    private List<Connection> pool;

    public MyConnection1(String hostToConnectTo, int portToConnectTo, Properties info, String databaseToConnectTo, String url, Connection connection, List<Connection> pool) throws SQLException {
        super(hostToConnectTo, portToConnectTo, info, databaseToConnectTo, url);
        this.connection = connection;
        this.pool = pool;
    }

    @Override
    public void close() throws SQLException {
        pool.add(connection);
    }

}
